/*
自己选择的路 ,跪着也要走完。朋友们 , 虽然这个世界日益浮躁起来,只
要能够为了当时纯粹的梦想和感动坚持努力下去 , 不管其它人怎么样,我
们也能够保持自己的本色走下去。
To the world , you will be a person , but to a person , you
will be the world .                               ——AKPower
*/
//作者:AKPower
//算法:
#include <iostream>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <vector>
#include <map>
#include <queue>
#include <cstdio>
#include <string>
#include <stack>
#include <set>
#define IOS ios::sync_with_stdio(false), cin.tie(0)
#define pa pair<ll, ll>
using namespace std;
typedef int ll;
const ll maxn = 1e6 + 100;
ll x[maxn];
ll cnt[100], cnt_s[100], cntx[maxn];
ll ans;
ll n, k;
map<ll, bool> vis;
map<ll, ll> mp;
vector<ll> v[100];
vector<ll> p[maxn];

bool judge(ll len, ll mid)
{
    ll i, j;
    ll anst = 0;
    memset(cnt, 0, sizeof(cnt));
    for (i = 1, j = 1; j <= len && x[j] - x[i] <= mid; j++)
    {
        for (ll k = 0; k < cntx[j]; k++)
        {
            ll ty = p[j][k];
            if (cnt[ty] == 0)
            {
                anst++;
            }
            cnt[ty]++;
        }
    }
    if (anst == k)
    {
        return true;
    }
    for (; j <= len; j++)
    {
        for (ll k = 0; k < cntx[j]; k++)
        {
            ll ty = p[j][k];
            if (cnt[ty] == 0)
            {
                anst++;
            }
            cnt[ty]++;
        }
        while (i < j && x[j] - x[i] > mid)
        {
            for (ll k = 0; k < cntx[i]; k++)
            {
                ll ty = p[i][k];
                cnt[ty]--;
                if (cnt[ty] == 0)
                {
                    anst--;
                }
            }
            i++;
        }
        if (anst == k)
        {
            return true;
        }
    }
    return false;
}

int main()
{
    IOS;
    cin >> n >> k;
    ll cn = 0;
    for (ll i = 1; i <= k; i++)
    {
        ll num, t;
        cin >> t;
        while (t--)
        {
            cin >> num;
            if (vis[num])
            {
                v[i].push_back(num);
            }
            else
            {
                vis[num] = true;
                x[++cn] = num;
                // x[cn].second=cn;
                v[i].push_back(num);
            }
            cnt_s[i]++;
        }
    }
    sort(x + 1, x + 1 + cn);
    for (ll i = 1; i <= cn; i++)
    {
        // cout << x[i] << " ";
        mp[x[i]] = i;
    }
    // cout << endl;
    for (ll i = 1; i <= k; i++)
    {
        for (ll j = 0; j < cnt_s[i]; j++)
        {
            ll xi = mp[v[i][j]];
            p[xi].push_back(i);
            cntx[xi]++;
        }
    }
    // for (ll i = 1; i <= cn; i++)
    // {
    //     for (ll j = 0; j < p[i].size(); j++)
    //     {
    //         cout << p[i][j] << " ";
    //     }
    //     cout << endl;
    // }
    ll l = 1, r = (1LL << 31) - 1;
    while (l <= r)
    {
        ll mid = (l + r) >> 1;
        if (judge(cn, mid))
        {
            r = mid - 1;
        }
        else
            l = mid + 1;
    }
    cout << l << endl;
    getchar();
    getchar();
    return 0;
}
